import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wallet_utils/ht_navigator.dart';

import 'color.dart';

Widget htAppbar({Widget? child, Color? backColor}) {
  return PreferredSize(
    preferredSize: const Size.fromHeight(kToolbarHeight),
    child: Container(
      color: backColor ?? Colors.white,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          SizedBox(
              width: double.infinity, height: 56, child: child ?? Container()),
        ],
      ),
    ),
  );
}

///默认常用appBar
PreferredSizeWidget htCommonAppbar(BuildContext context,
    {Color? backgroundColor,
    String? title,
    Text? textTitle,
    TextStyle? titleStyle,
    PreferredSizeWidget? bottom,
    Brightness? brightness,
    double? elevation,
    VoidCallback? leadingAction,
    Widget? leading,
    List<Widget>? rightActionListWidget}) {
  return AppBar(
    brightness: brightness ?? Brightness.light,
    backgroundColor: backgroundColor ?? Colors.white,
    elevation: elevation ?? 0,
    shadowColor: Colors.transparent,
    centerTitle: true,
    toolbarHeight: 44.w,
    title: textTitle ??
        Text(
          title!,
          style: titleStyle ?? TextStyle(
              fontWeight: FontWeight.w500,
              color: ColorManager.color2A2A2A,
              fontSize: 18.sp),
        ),
    leading: leading ??
        backWidgetAction(
            backAction: leadingAction ?? () => HTNavigator.pop(context)),
    actions: rightActionListWidget,
    bottom: bottom,
  );
}

PreferredSizeWidget htCommonAppbarNoBackBtn(BuildContext context,
    {Color? backgroundColor,
    String? title,
    Text? textTitle,
    PreferredSizeWidget? bottom,
    Brightness? brightness,
    double? elevation,
    VoidCallback? leadingAction,
    List<Widget>? rightActionListWidget}) {
  return AppBar(
    brightness: brightness ?? Brightness.light,
    backgroundColor: backgroundColor ?? Colors.white,
    elevation: elevation ?? 0,
    shadowColor: Colors.transparent,
    centerTitle: true,
    title: textTitle ??
        Text(
          title!,
          style: TextStyle(
              fontWeight: FontWeight.w500,
              color: ColorManager.color2A2A2A,
              fontSize: 18.sp),
        ),
    automaticallyImplyLeading: false,
    actions: rightActionListWidget,
    bottom: bottom,
  );
}

Widget htCustomAppBar(BuildContext context, {Widget? child, Color? backColor}) {
  return Container(
    height: kToolbarHeight + MediaQuery.of(context).padding.top,
    color: backColor ?? Colors.white,
    child: Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Container(
            width: double.infinity, height: 56, child: child ?? Container()),
      ],
    ),
  );
}

Widget backWidgetAction({VoidCallback? backAction, Color? color}) {
  return IconButton(
      icon: Image.asset(
        "images/back.png",
        width: 22.w,
        height: 22.w,
        color: color,
      ),
      onPressed: backAction);
}
